﻿<style type="text/css">
    body, html {
        width: 100%;
        height: 100%;
        margin: 0;
        font-family: "微软雅黑";
    }

    #l-map {
        height: 400px;
        width: 100%;
    }

    #r-result {
        width: 100%;
        font-size: 14px;
        line-height: 20px;
    }
</style>


<div ms-controller="tempview">


    <label class="control-label"><b style="color: #f00;">*</b>订单详情</label>
    <div>
        <table class="sui-table table-primary table-zebra">
            <thead>
                <tr>
                    <th>订单号</th>
                    <th>装车地址</th>
                    <th>车辆</th>


                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-el="ListData">
                    <td>{{el.ORDERID}}</td>
                    <td>{{el.PUTONADD}}</td>
                    <td><input type="text" id="txtcarid"  ms-duplex="ModelData.carid" /></td>
                </tr>
            </tbody>
        </table>
    </div>

    <label class="control-label"><b style="color: #f00;">*</b>附近车辆：</label>
    <div>

        <table class="sui-table table-primary table-zebra">
            <thead>
                <tr>
                    <th>选择</th>
                    <th>装车地址</th>
                    <th>车辆</th>


                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-el="ListData1">
                    <td><input type="checkbox" /></td>
                    <td>{{el.PUTONADD}}</td>
                    <td>{{el.CARID}}</td>
                </tr>
            </tbody>
        </table>
    </div>
    <br />
    <input type="button" value="查看装货位置" onclick="bdGEO()" />
    <div id="l-map"></div>
    <div id="r-result">

        <div id="result"></div>
    </div>
</div>

<script type="text/javascript">


    var orderid = ComFunJS.getQueryString("order");
    var beginadd = ComFunJS.getQueryString("beginadd");

    // 百度地图API功能
    var map = new BMap.Map("l-map");
    map.centerAndZoom(new BMap.Point(118.68127, 24.881026), 15);
    map.enableScrollWheelZoom(true);
    var index = 0;
    var myGeo = new BMap.Geocoder();
    var adds = [
        //"泉州市人民政府",
        //"泉州星宿客栈",
        //"泉州东海湾实验学校",
        //"鸡笼山 ",
        //"泉州市旅游局",
        //"海星小区",
        //"宝秀小区",
        //"泉州迎宾馆"
    ];

   
    function bdGEO() {
        
        for (var i = 0; i < tempmodel.ListData2.length; i++) {
            //adds.add(tempmodel.ListData2[i]["PUTONADD"]);
            adds[i] = tempmodel.ListData2[i]["PUTONADD"];
            //alert(tempmodel.ListData2[i]["PUTONADD"]);
        }
        //alert(adds[0]);
        //alert(adds[1]);
        //alert(adds[2]);
        //alert(adds[1]);
        var add = adds[index];
        geocodeSearch(add);
        index++;
    }
    function geocodeSearch(add) {
        if (index < adds.length) {
            setTimeout(window.bdGEO, 400);
        }
        myGeo.getPoint(add, function (point) {
            if (point) {
                document.getElementById("result").innerHTML += index + "、" + add + ":" + point.lng + "," + point.lat + "</br>";
                var address = new BMap.Point(point.lng, point.lat);
                addMarker(address, new BMap.Label(index + ":" + add, { offset: new BMap.Size(20, -10) }));
            }
        }, "泉州市");
    }
    // 编写自定义函数,创建标注
    function addMarker(point, label) {
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        marker.setLabel(label);
    }
   


    
    var tempmodel = avalon.define({
        $id: "tempview",
        ModelData: {"carid":""},
        searchkey: "",
        Type2: "",
        TypeList1: [],
        TypeList2: [],
        IsShelf: "",
        ToTop: "",
        page: { pageindex: 1, pagesize: 10 },
        total: 0,
        ListData: [],
        ListData1: [],
        ListData2: [],
        Init: function () {
            
            $.getJSON("/adapi/base/order/list", function (r) {
                tempmodel.TypeList1 = r.result;
            })
            tempmodel.GetLIST();
            tempmodel.GetLIST1();
            tempmodel.GetLIST2();
            
        },
        GetLIST: function () {
            tempmodel.page.pageindex = 1;
            tempmodel.ListData.clear();
           
            $.getJSON("/adapi/base/order/list", { pageindex: tempmodel.page.pageindex, pagesize: tempmodel.page.pagesize, "searchkey": orderid }, function (r) {
                if (r.error == "") {
                    tempmodel.ListData = r.result;
                    tempmodel.total = r.total;

                    $("#pageDiv").pagination({  //分页容器
                        styleClass: ['sui-pagination'],  //分页样式
                        //showCtrl: false,
                        displayPage: 6,
                        itemsCount: r.total,
                        pageSize: tempmodel.page.pagesize,
                        onSelect: function (num) {
                            model.page.pageindex = num;
                            $.getJSON("/adapi/base/order/list", { pageindex: tempmodel.page.pageindex, pagesize: tempmodel.page.pagesize, "searchkey": orderid }, function (r) {
                                tempmodel.ListData.clear();
                                tempmodel.ListData = r.result;
                            })
                        }
                    })

                    $('#pageDiv').pagination('updateItemsCount', r.total, 1);
                }
            })
        },
        GetLIST1: function () {
            //tempmodel.page.pageindex = 1;
            tempmodel.ListData1.clear();

            $.getJSON("/adapi/base/transfer/list", function (r) {
                if (r.error == "") {
                    tempmodel.ListData1 = r.result;
                   

                }
            })
        },
        GetLIST2: function () {
            //tempmodel.page.pageindex = 1;
            tempmodel.ListData1.clear();

            $.getJSON("/adapi/base/transfer1/list", function (r) {
                if (r.error == "") {
                    tempmodel.ListData2 = r.result;
                    //adds = tempmodel.ListData2;

                }
            })
        },
        //保存
        tmpSaveData: function () {

           
           // alert(ModelData.carid);
            var carid = document.getElementById("txtcarid").value;

            var info = orderid + "*" + carid;

            $.post("/adapi/base/updatecar", { "carid": carid, "orderid": orderid }, function (r) {
                if (r.error == "") {
                    top.ComFunJS.winShowMsg("操作成功");
                    top.ComFunJS.close();
                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }

            })
        }


    })



</script>